home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
MoreKittiesPlease
/
Source
/
CBasicApp.cp
next >
Wrap
Text File
|
2000-06-23
|
7KB
|
287 lines
// ===========================================================================
// CBasicApp.cp ©1994-1999 Metrowerks Inc. All rights reserved.
// ===========================================================================
// This file contains the starter code for a basic PowerPlant project
#include "CBasicApp.h"
#include <LGrowZone.h>
#include <PP_Messages.h>
#include <PP_Resources.h>
#include <UDrawingState.h>
#include <UMemoryMgr.h>
#include <URegistrar.h>
#include <LWindow.h>
#include <LCaption.h>
#include <LStdControl.h>
#include <DCon.h>
#import <OpenTransport.h>
#import <OpenTptClient.h>
#import <OTSharedLibs.h>
#import <UModaldialogs.h>
#import <LInternetAddress.h>
#import <UThread.h>
#import <LThread.h>
#import <cstdio>
#import "OTAutoPush.h"
#import "Kitties_Module.h"
#define kModuleName "MoreKittiesMod"
// Constant declarations
const ResIDT PPob_SampleWindow = 128;
// ===========================================================================
// • main
// ===========================================================================
int main()
{
// Set Debugging options
SetDebugThrow_(debugAction_Alert);
SetDebugSignal_(debugAction_Alert);
// Initialize Memory Manager. Parameter is the number of
// master pointer blocks to allocate
InitializeHeap(3);
// Initialize standard Toolbox managers
UQDGlobals::InitializeToolbox(&qd);
// Install a GrowZone to catch low-memory situations
new LGrowZone(20000);
new UMainThread;
// Create the application object and run
CBasicApp theApp;
theApp.Run();
return 0;
}
// ---------------------------------------------------------------------------
// • CBasicApp [public]
// ---------------------------------------------------------------------------
// Application object constructor
CBasicApp::CBasicApp():
moduleLibrary(0)
{
RegisterClasses();
}
// ---------------------------------------------------------------------------
// • ~CBasicApp [public, virtual]
// ---------------------------------------------------------------------------
// Application object destructor
CBasicApp::~CBasicApp()
{
// Nothing
}
// ---------------------------------------------------------------------------
// • StartUp [protected, virtual]
// ---------------------------------------------------------------------------
// Perform an action in response to the Open Application AppleEvent.
// Here, issue the New command to open a window.
void
CBasicApp::StartUp()
{
if ((long) OTAPRegisterAutoPushOnTCP ==
kUnresolvedCFragSymbolAddress ) {
UModalAlerts::Alert( kAlert_NeedsAutoPush );
ObeyCommand( cmd_Quit, nil );
}
ObeyCommand(cmd_New, nil);
}
void
CBasicApp::Unload()
{
OSStatus err;
if ( moduleLibrary ) {
err = OTAPUnregisterAutoPushOnUDP( kModuleName );
dprintf( "OTAPUnregisterAutoPushOnUDP error was %d\n", err );
err = OTAPUnregisterAutoPushOnTCP( kModuleName );
dprintf( "OTAPUnregisterAutoPushOnTCP error was %d\n", err );
OTReleaseCFMConnection( &moduleLibrary );
moduleLibrary = 0;
dprintf( "Unload\n" );
} else {
dprintf( "Not loaded\n" );
}
}
void
CBasicApp::Load()
{
OSStatus err;
if ( !moduleLibrary ) {
err = OTLoadCFMLibrary("OTModl$MoreKittiesMod", &moduleLibrary, kOTLoadACopy);
dprintf( "OTLoadCFMLibrary error was %d\n", err );
err = OTAPRegisterAutoPushOnTCP( kModuleName );
dprintf( "OTAPRegisterAutoPushOnTCP error was %d\n", err );
err = OTAPRegisterAutoPushOnUDP( kModuleName );
dprintf( "OTAPRegisterAutoPushOnUDP error was %d\n", err );
dprintf( "Load\n" );
} else {
dprintf( "Already loaded\n" );
}
}
UInt32
CBasicApp::GetFlags()
{
return (m3133T->GetValue() ? k3133t: 0) |
(mHeaders->GetValue() ? kHeaders: 0) |
(mHamster->GetValue() ? kHamsters: 0) |
(mKitties->GetValue() ? kKittiesFlag: 0);
}
void
CBasicApp::ListenToMessage( MessageT inMessage,
void* )
{
SetFilterFunc routine;
switch (inMessage) {
case cmd_Set:
dprintf( "set called with %x\n", GetFlags() );
if ( moduleLibrary ) {
routine = (SetFilterFunc)OTGetCFMSymbol("SetFilter", moduleLibrary, kOTGetCodeSymbol);
if ( routine ) {
(*routine)( GetFlags() );
} else {
dprintf( "Could not find symbol for SetFilterFunc\n" );
}
}
break;
case cmd_Unload:
Unload();
break;
case cmd_Load:
Load();
break;
default: {
break;
}
}
}
// ---------------------------------------------------------------------------
// • ObeyCommand [public, virtual]
// ---------------------------------------------------------------------------
// Respond to Commands. Returns true if the Command was handled, false if not.
Boolean
CBasicApp::ObeyCommand(
CommandT inCommand,
void* ioParam)
{
Boolean cmdHandled = true; // Assume we'll handle the command
switch (inCommand) {
case cmd_New: {
LWindow* theWindow = LWindow::CreateWindow(PPob_SampleWindow, this);
ThrowIfNil_(theWindow);
UReanimator::LinkListenerToBroadcasters( this,
theWindow,
PPob_SampleWindow );
m3133T = (LStdCheckBox *)theWindow->FindPaneByID( id_3133T );
if ( !m3133T ) {
dprintf( "m3133T was not found\n" );
}
mHeaders = (LStdCheckBox *)theWindow->FindPaneByID( id_Headers );
if ( !m3133T ) {
dprintf( "mHeaders was not found\n" );
}
mKitties = (LStdCheckBox *)theWindow->FindPaneByID( id_Kitties );
if ( !m3133T ) {
dprintf( "mKitties was not found\n" );
}
mHamster = (LStdCheckBox *)theWindow->FindPaneByID( id_Hamster );
if ( !m3133T ) {
dprintf( "mHamster was not found\n" );
}
theWindow->Show();
break;
}
case cmd_Quit:
Unload();
//fall through
default: {
cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
break;
}
}
return cmdHandled;
}
// ---------------------------------------------------------------------------
// • FindCommandStatus [public, virtual]
// ---------------------------------------------------------------------------
// Determine the status of a Command for the purposes of menu updating.
void
CBasicApp::FindCommandStatus(
CommandT inCommand,
Boolean& outEnabled,
Boolean& outUsesMark,
UInt16& outMark,
Str255 outName)
{
switch (inCommand) {
case cmd_New: {
outEnabled = true;
break;
}
default: {
LApplication::FindCommandStatus(inCommand, outEnabled,
outUsesMark, outMark, outName);
break;
}
}
}
// ---------------------------------------------------------------------------
// • RegisterClasses [protected]
// ---------------------------------------------------------------------------
// To reduce clutter within the Application object's constructor, class
// registrations appear here in this seperate function for ease of use.
void
CBasicApp::RegisterClasses()
{
RegisterClass_(LWindow);
RegisterClass_(LCaption);
RegisterClass_(LStdButton);
RegisterClass_(LStdCheckBox);
RegisterClass_(LEditField);
}